//
//  ChoicenessCell.m
//  IntimateGift
//
//  Created by zh on 14/12/17.
//  Copyright (c) 2014年 蔡宏业. All rights reserved.
//

#import "ChoicenessCell.h"
#import "UIImageView+WebCache.h"
@interface ChoicenessCell ()


@end

@implementation ChoicenessCell

// 初始化
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        // 背景白色
        self.backView = [[UIView alloc] init];
        self.backView.backgroundColor = [UIColor whiteColor];
        [self.contentView addSubview:self.backView];
        // 图片
        self.myImageView = [[UIImageView alloc] init];
        self.myImageView.backgroundColor = [UIColor blackColor];
        [self.backView addSubview:self.myImageView];
        // 标题
        self.titleLabel = [[UILabel alloc] init];
        self.titleLabel.textColor = [UIColor whiteColor];
        [self.myImageView addSubview:self.titleLabel];
        [_titleLabel release];
        // 喜欢个数的背景
        self.likeImageView = [[UIImageView alloc] init];
        self.likeImageView.backgroundColor = [UIColor blackColor];
        self.likeImageView.userInteractionEnabled = YES;
        self.likeImageView.layer.cornerRadius = 12;
//        UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapAction:)];
//        [self.likeImageView addGestureRecognizer:tap];
        self.likeImageView.alpha = 0.5;
        [self.myImageView addSubview:self.likeImageView];
        // 喜欢个数
        self.likeLabel = [[UILabel alloc] init];
        [self.likeImageView addSubview:self.likeLabel];
        self.likeLabel.textColor = [UIColor whiteColor];
        self.likeLabel.textAlignment = NSTextAlignmentCenter;
        self.likeLabel.font = [UIFont systemFontOfSize:14];
        [_likeLabel release];
        // 心形图片
        self.heartImageView = [[UIImageView alloc] init];
        [self.likeImageView addSubview:self.heartImageView];
        self.heartImageView.image = [UIImage imageNamed:@"iconfont-xin.png"];
//        self.heartImageView.backgroundColor = [UIColor clearColor];
        [_heartImageView release];
        
        self.likeButton = [UIButton buttonWithType:UIButtonTypeSystem];
        [self.contentView addSubview:self.likeButton];
        self.likeButton.backgroundColor = [UIColor clearColor];
        
        [_likeImageView release];
        [_myImageView release];
        [_backView release];
        
    }
    return self;
    
}



- (void)layoutSubviews
{
    [super layoutSubviews];
    // 上面控件的坐标
    _backView.frame = CGRectMake(5, 5, self.contentView.bounds.size.width - 10, self.contentView.bounds.size.height - 10);
    _myImageView.frame = CGRectMake(5, 5, self.backView.bounds.size.width - 10, self.backView.bounds.size.height - 10);
    _titleLabel.frame = CGRectMake(5, self.myImageView.bounds.size.height - self.myImageView.bounds.size.height / 5, self.myImageView.bounds.size.width - 10, self.myImageView.bounds.size.height / 5);
    _likeImageView.frame = CGRectMake(self.myImageView.bounds.size.width - self.myImageView.bounds.size.width / 5, 5, self.myImageView.bounds.size.width / 5 - 5, 30);
//    _heartImageView.frame = CGRectMake(self.likeImageView.bounds.size.width - 2, self.likeImageView.bounds.size.height - 2, self.likeImageView.bounds.size.width / 3, self.likeImageView.bounds.size.height - 4);
    _heartImageView.frame = CGRectMake(2, 5, 15, 20);
    _likeLabel.frame = CGRectMake(15, 5, 40, 20);
    _likeButton.frame = CGRectMake(self.contentView.bounds.size.width - 15 - (self.myImageView.bounds.size.width / 5 - 5), 15, self.myImageView.bounds.size.width / 5 - 5, 30);
    
}

// 重写setter方法
- (void)setChoiceness:(Choiceness *)choiceness
{
    if (_choiceness != choiceness) {
        [_choiceness release];
        _choiceness = [choiceness retain];
    }
    [_myImageView setImageWithURL:[NSURL URLWithString:_choiceness.cover_image_url] placeholderImage:[UIImage imageNamed:@"zhanwei.jpg"]];
    _titleLabel.text = _choiceness.title;
    _likeLabel.text = _choiceness.likes_count;
    
}

// 内存
- (void)dealloc
{
    [_backView release];
    [_myImageView release];
    [_titleLabel release];
    [_likeImageView release];
    [_likeLabel release];
    [_heartImageView release];
    [super dealloc];
}

- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
